<?php

namespace app\admin\controller;

use think\facade\Db;

class Config extends Base
{
    protected $tb = "config";
    public function index()
    {
        $configData1 = Db::name($this->tb)->where('config_type',1)->order('id desc')->select();
        $configData2 = Db::name($this->tb)->where('config_type',2)->order('id desc')->select();
        if (request()->isPost()){
            $data = input('post.');
            foreach ($data as $key=>$v){
                Db::name($this->tb)->where('id',$key)->update(['value' => $v]);
            }
            return alert("操作成功",'index',6);
        }
        $loginData = [];
        return view('',[
            'configData1' => $configData1,
            'configData2' => $configData2,
        ]);
    }

    public function del_cache()
    {
        $path = root_path() . "runtime";
        delFileByDir($path);
        return alert('清空缓存成功','/admin/index/welcome',6);

    }

    public function notice()
    {
        $noticeData = Db::name("notice")->order("id desc")->paginate(10);
        return view('',[
            'noticeData' => $noticeData,
        ]);
    }

    public function notice_send(){
        if (request()->isPost()){
            $data = input('post.');
            Db::name("notice")->insert($data);
            return alert('操作成功','notice',6);
        }
        return view('',[]);
    }

    public function notice_edit()
    {
        $id = request()->param('id');
        $noticeData = Db::name("notice")->find($id);
        if (request()->isPost()){
            $data = input('post.');
            Db::name('notice')->update($data);
            return alert('操作成功','notice',6);
        }
        return view('',[
            'noticeData' => $noticeData
        ]);
    }


}
